<template>
  <view class="page" style="position: fixed">
    <view class="header align-center" @click="$to('/pages/editUser/index')">
      <image class="avatar" mode="aspectFill" :src="userInfo.avatar" />
      <view class="name">{{ userInfo.nickname }}</view>
    </view>

    <view class="navList" style="">
      <view class="justify-between">
        <view class="navItem" v-for="(item, index) in navList" :key="index" @click="$to(item.url)">
          <image class="incoImg" referrerpolicy="no-referrer" :src="item.lanhuimage0" />
          <view class="item-text mt10">{{ item.lanhutext0 }}</view>
        </view>
      </view>
    </view>

    <view class="menuList">
      <view class="menuItem justify-between" @click="goPath(item.url)" v-for="(item, index) in menuList" :key="item.lanhutext0">
        <view class="align-center">
          <image class="incoImg mr10" referrerpolicy="no-referrer" :src="item.lanhuimage0" />
          <view class="item-text"> {{ item.lanhutext0 }}</view>
        </view>
        <view class="align-center">
          <view class="item-text" v-if="index == 0"> {{ xiaoxi }}</view>
          <view class="item-text" v-if="index == 1">{{ shoucang }}</view>
          <view class="item-text" v-if="index == 3">{{ renzheng }}</view>
          <uni-icons type="right" size="20"></uni-icons>
        </view>
      </view>
    </view>

    <tabbar :index="2"></tabbar>
  </view>
</template>

<script>
import tabbar from '@/components/tabbar.vue'

export default {
  components: {
    tabbar
  },
  data() {
    return {
      xiaoxi: 0,
      shoucang: 0,
      renzheng: '',
      user_id: '',
      islogn: 0,
      navList: [
        {
          lanhuimage0: require('@/static/user/n1.png'),
          lanhutext0: '浏览记录',
          url: '/pages/pageView/index'
        },
        {
          lanhuimage0: require('@/static/user/n2.png'),
          url: '/pages/draft/index',
          lanhutext0: '我的草稿'
        },
        {
          lanhuimage0: require('@/static/user/n3.png'),
          url: '/pages/myTrading/index',
          lanhutext0: '我的成交'
        },
        {
          lanhuimage0: require('@/static/user/n4.png'),
          url: '/pages/myInterest/index',
          lanhutext0: '我的关注'
        }
      ],
      menuList: [
        {
          lanhuimage0: require('@/static/user/l1.png'),
          lanhutext0: '我的消息',
          url: '/pages/myMessage/index'
        },
        {
          lanhuimage0: require('@/static/user/l2.png'),
          url: '/pages/myFavorite/index',
          lanhutext0: '我的收藏'
        },
        {
          lanhuimage0: require('@/static/user/l3.png'),
          lanhutext0: '我的评价',
          url: '/pages/myReview/index'
        },
        {
          lanhuimage0: require('@/static/user/l4.png'),
          lanhutext0: '用户信息',
          url: 'card'
        }
      ],
      constants: {},
      userInfo: {}
    }
  },
  onShow() {
    setTimeout(() => {
      this.$http({
        url: 'getUserInfo'
      }).then(res => {
        this.$db.setUser(res.data.myself)
        this.userInfo = res.data.myself
      })
      this.getData()
    }, 100)
  },
  methods: {
    getData() {
      this.renzheng = ''
      var that = this
      uni.request({
        url: this.$global.baseUrl + 'getMydata',
        method: 'GET',
        header: {
          token: this.$db.getToken()
        },
        success: res => {
          that.xiaoxi = res.data.data.xiaoxi
          that.shoucang = res.data.data.shoucang
          that.renzheng = res.data.data.renzheng
        }
      })
    },
    goPath(url) {
      if (url == 'card') {
        return this.realName()
      }
      this.$to(url)
    },
    realName() {
      this.$http({
        url: 'realNameStatus',
        data: {
          user_id: this.userInfo.id
        }
      }).then(res => {
        //审核通过
        if (res.data == 1) {
          uni.navigateTo({
            url: '/pages/authentication/index?status=1'
          })
        }
        if (res.data == 2) {
          //审核拒绝
          uni.navigateTo({
            url: '/pages/authentication/index?status=2'
          })
        }
        if (res.data == 3) {
          uni.navigateTo({
            url: '/pages/realNameAuthentication/index'
          })
        }

        if (res.data == 4) {
          uni.navigateTo({
            url: '/pages/authentication/index?status=4'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../common/common.css';
.page {
  background-color: rgba(248, 248, 248, 1);
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
.item-text {
  font-size: 13px;
  color: #333333;
  height: auto;
}
.menuItem {
  display: flex;
  align-items: center;
  height: 60px;
  border-bottom: 1px solid #f9f9f9;
}
.header {
  background: url(/static/user/bac.png) no-repeat center;
  background-size: 100% 100%;
  padding: 0px 12rpx 28rpx 18rpx;
  height: 200px;
  padding-top: calc(var(--status-bar-height) + 40px);
}

.avatar {
  width: 82px;
  height: 82px;
  margin-right: 10px;
  border-radius: 50px;
}

.navList {
  background-color: rgba(255, 255, 255, 1);
  border-radius: 8px;
  align-self: center;
  margin-top: -8rpx;
  width: 95%;
  margin: 10px auto;
  padding: 28rpx 36rpx 28rpx 36rpx;
}

.incoImg {
  width: 50rpx;
  height: 50rpx;
  display: block;
}

.menuList {
  background-color: rgba(255, 255, 255, 1);
  border-radius: 8px;
  padding: 20px;
  margin: 10px auto;
  width: 95%;
  margin-top: 10px;
}
.navItem {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
</style>
